<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/view/include/taglib.jsp"%>
<html lang="cn" class="app">
<head>
    <title>消息管理 - 站内信</title>
    <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <link rel="icon" type="image/png" href="icon.png">
    <link rel="apple-touch-icon-precomposed" href="icon.png">
    <link rel="stylesheet" href="${ctxStatic}/css/bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/css/app.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/js/ztree/css/zTreeStyle.css" />
    <link rel="stylesheet" href="${ctxStatic}/js/chosen/chosen.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/js/layui/css/layui.css">
    <!--[if lt IE 9]>
    <script src="${ctxStatic}/js/ie/html5shiv.js"></script>
    <script src="${ctxStatic}/js/ie/respond.min.js"></script>
    <script src="${ctxStatic}/js/ie/excanvas.js"></script>
    <![endif]-->
</head>

<body>
<section class="scrollable wrapper">
    <div class="row">
        <div class="col-lg-12">
            <!-- 引导开始 -->
            <ul class="breadcrumb">
                <li><a href="${ctx}/welcome"><i class="fa fa-home"></i> 主页</a></li>
                <li>消息管理</li>
                <li class="active">站内信</li>
                <li class="active">站内信新增</li>
            </ul>
            <!-- 引导结束 -->
        </div>
    </div>
    <form id="msgMailForm" class="bs-example form-horizontal" method="post" >

        <%--基本信息--%>
        <section class="panel panel-default">
            <input id="type" type="hidden" class="form-control" name="type" value="mail"   required/>
            <input id="objectId" type="hidden" class="form-control" name="objectId" value="1"   required/>
            <input id="msgType" type="hidden" class="form-control" name="msgType" value="1"   required/>

            <div class="panel-body">
                    <div class="form-group">
                        <label class="col-lg-2 col-md-2 col-sm-2 control-label"><span class="text-danger">*</span>标题：</label>
                        <div class="col-lg-10 col-md-10 col-sm-10">
                            <input id="title" type="text" class="form-control" name="title" maxlength="200"  required/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-2 col-md-2 col-sm-2 control-label"><span class="text-danger">*</span>接收人：</label>
                        <div class="col-lg-10 col-md-10 col-sm-10">
                            <select id="users" name="users"  style="width:100%;margin-top:5px;height: 34px" class="chosen-select" data-maxlength="200" data-placeholder="请选择人员" multiple="multiple">
                                <c:forEach items="${userList}" var="item">
                                    <option value="${item.id}">${item.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-2 col-md-2 col-sm-2 control-label"><span class="text-danger">*</span>内容：</label>
                        <div class="col-lg-10 col-md-10 col-sm-10">
                            <script id="contentScript" type="text/plain" style="height:300px;" >${msgReceive.msgSend.content}</script>
                            <textarea id="content" class="form-control" name="content" style="display: none;"></textarea>
                            <textarea id="contentText" class="form-control" name="contentText" style="display: none;"></textarea>
                         </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-2 col-lg-10 col-md-10 col-sm-10">
                            <shiro:hasPermission name="sys:msgMailReceive:create">
                                <button type="button" class="btn btn-s-md btn-info" onclick="insertMsgMail()">保存</button>
                            </shiro:hasPermission>
                            <button type="button" class="btn btn-s-md btn-danger" onclick="closeModel(false)">关闭</button>
                        </div>
                    </div>
            </div>
        </section>

    </form>
</section>

</body>

<script src="${ctxStatic}/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="${ctxStatic}/js/bootstrap.js"></script>
<!-- App -->
<script type="text/javascript" src="${ctxStatic}/js/page/paging.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/layer/layer.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/tmpl/jquery.tmpl.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/chosen/chosen.jquery.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/layui/layui.all.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctxStatic}/js/uEditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctxStatic}/js/uEditor/ueditor.all.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="${ctxStatic}/js/uEditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/tools.js?version=${ctxVersion}"></script>
<!-- 实例化编辑器 -->
 <script type="text/javascript">
    var ue = UE.getEditor('contentScript');
 </script>
<script>
    $(function(){
        $(".chosen-select").chosen();//初始化带搜索下拉框，自带初始化宽度显示非100%bug
    })

    function insertMsgMail(){
        var html = ue.getContent();
        var txt = ue.getContentTxt();
        $("#content").val(html);
        $("#contentText").val(txt);
        if(isBlankCheck("title","标题")){
            if(checkContentEmpty()){
            var loadingLayer = layer.load(1, {shade: [0.1,'#fff']});//loading
            //根据项目标识获取目录
            $.ajax({
                type: 'post',
                url: '${ctx}/sys/msgMailReceive/create.json?timeStamp='+new Date().getTime(),
                dataType:"json",
                data: $("#msgMailForm").serialize(),
                success: function (data) {
                    layer.close(loadingLayer);
                    showMsg(data.desc,function(){
                        if(data.ret==1) {//成功
                            location.href = "${ctx}/sys/msgMailReceive/list?id=" + data.data;
                        }
                    });
                },error:function(){
                    layer.close(loadingLayer);
                    layer.msg('网络异常', {time: 5000, icon:6});

                }
            });
        }
        }
    }

</script>
<script>
    function checkContentEmpty() {
        var msg = "";
        var id = "";
        if (!$("#content").val()) {
            msg = "请输入内容";
            id = "#content";
        }
        if (null==$("#users").val()) {
            msg = "请选择人员";
            id = "#users";
        }
        if(msg&&id){
            checkTip(msg,id);
            return false;
        }
        return true;
    }
    /**对应提示空内容*/
    function checkTip(msg,id) {
        layer.tips(msg, id,{
            tips: [1,'#3595CC'],
            time: 2000
        });
    }
</script>
</html>
